package org.alanlau.mybatisannodemo.mapper;

import org.alanlau.mybatisannodemo.po.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    @Select("select * from user")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "age", column = "age"),
            @Result(property = "sex", column = "sex")
    })
    List<User> getAll();

    @Select("select * from user where id=#{id}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "age", column = "age"),
            @Result(property = "sex", column = "sex")
    })
    User getById(String id);

    @Insert("insert into user (id,name,age,sex) values (#{id},#{name},#{age},#{sex})")
    void insert(User user);

    @Update("update user set name=#{name},age=#{age},sex=#{sex} where id=#{id}")
    void update(User user);

    @Delete("delete from user where id=#{id}")
    void delete(String id);
}
